package com.party.core.service.crowdfund.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.crowdfund.MemberWithdrawalFundReadDao;
import com.party.core.dao.write.crowdfund.MemberWithdrawalFundWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.crowdfund.MemberWithdrawalFund;
import com.party.core.model.wallet.CrowdfundEventWithdrawalsOutput;
import com.party.core.service.crowdfund.IMemberWithdrawalFundService;
import com.sun.istack.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 会员提现资金接口实现R
 * Created by hqh
 *
 * @date 2018/10/10 0025
 * @time 19:25
 */

@Service
public class MemberWithdrawalFundService implements IMemberWithdrawalFundService {

    @Autowired
    private MemberWithdrawalFundReadDao memberWithdrawalFundReadDao;

    @Autowired
    private MemberWithdrawalFundWriteDao memberWithdrawalFundWriteDao;



    /**
     * 插入会员提现资金
     * @param memberWithdrawalFund 会员提现资金
     * @return 事件编号
     */
    @Override
    public String insert(MemberWithdrawalFund memberWithdrawalFund) {
        BaseModel.preInsert(memberWithdrawalFund);
        boolean result = memberWithdrawalFundWriteDao.insert(memberWithdrawalFund);
        if (result){
            return memberWithdrawalFund.getId();
        }
        return null;
    }

    /**
     * 更新会员提现资金
     * @param memberWithdrawalFund 会员提现资金
     * @return 更新结果（true/false）
     */
    @Override
    public boolean update(MemberWithdrawalFund memberWithdrawalFund) {
        if (null != memberWithdrawalFund) {
            memberWithdrawalFund.setUpdateDate(new Date());
        }
        return memberWithdrawalFundWriteDao.update(memberWithdrawalFund);
    }

    /**
     * 逻辑删除会员提现资金
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return memberWithdrawalFundWriteDao.deleteLogic(id);
    }

    /**
     * 物理删除会员提现资金
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return memberWithdrawalFundWriteDao.delete(id);
    }

    /**
     * 批量逻辑删除会员提现资金
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return memberWithdrawalFundWriteDao.batchDeleteLogic(ids);
    }

    /**
     * 批量物理删除会员提现资金
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return memberWithdrawalFundWriteDao.batchDelete(ids);
    }

    /**
     * 根据编号获取
     * @param id 主键
     * @return 会员提现资金
     */
    @Override
    public MemberWithdrawalFund get(String id) {
        return memberWithdrawalFundReadDao.get(id);
    }

    /**
     * 会员提现资金列表
     * @param memberWithdrawalFund 会员提现资金
     * @param page 分页信息
     * @return 事件列表
     */
    @Override
    public List<MemberWithdrawalFund> listPage(MemberWithdrawalFund memberWithdrawalFund, Page page) {
        return null;
    }

    /**
     * 所有会员提现资金
     * @param memberWithdrawalFund 会员提现资金
     * @return 会员提现资金
     */
    @Override
    public List<MemberWithdrawalFund> list(MemberWithdrawalFund memberWithdrawalFund) {
        return null;
    }


    /**
     * 批量查询会员提现资金
     * @param ids 主键集合
     * @param memberWithdrawalFund 众筹事件
     * @param page 分页信息
     * @return 事件列表
     */
    @Override
    public List<MemberWithdrawalFund> batchList(@NotNull Set<String> ids, MemberWithdrawalFund memberWithdrawalFund, Page page) {
        return null;
    }

    /**
	 * 通过订单的支付时间查询所有机构的众筹成功的可提现金额
	 *
	 * @param queryDate 查询时间
	 * @return
	 */
    @Override
    public List<MemberWithdrawalFund> getMemberEventWithdrawalFund(String queryDate,Map<String,Object> params) {
        return memberWithdrawalFundReadDao.getMemberEventWithdrawalFund(queryDate,params);
    }

    /**
     * 通过订单的支付时间查询所有机构的众筹成功的人数
     *
     * @param eventId 主题id
     * @param queryDate 查询时间
     * @return
     */
    @Override
    public Integer countBySuccessDate(String eventId, String queryDate,Integer sign,Map<String,Object> params) {
        return memberWithdrawalFundReadDao.countBySuccessDate(eventId,queryDate,sign,params);
    }

    /**
     * 通过MemberWithdrawalFund实体查询
     *
     * @param memberWithdrawalFund
     * @return
     */
    @Override
    public MemberWithdrawalFund findByMemberWithdrawalFund(MemberWithdrawalFund memberWithdrawalFund) {
        return memberWithdrawalFundReadDao.findByMemberWithdrawalFund(memberWithdrawalFund);
    }


    /**
     * 通过MemberWithdrawalFund实体查询总可提现金额
     *
     * @param memberWithdrawalFund
     * @return
     */
    @Override
    public Double getMemberCanWithdrawAmount(MemberWithdrawalFund memberWithdrawalFund) {
        return memberWithdrawalFundReadDao.getMemberCanWithdrawAmount(memberWithdrawalFund);
    }

    /**
     * 通过memberId实体查询机构下的可提现主题
     *
     * @param memberId
     * @return
     */
    @Override
    public List<CrowdfundEventWithdrawalsOutput> getMemberEventWithdrawalList(String memberId,Page page) {
        return memberWithdrawalFundReadDao.getMemberEventWithdrawalList(memberId,page);
    }
}
